home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Freeware / DiskMaster / Rexx / DMExecOnMany.rexx < prev    next >
OS/2 REXX Batch file  |  2002-10-27  |  2KB  |  84 lines

  1. /* $VER: DMExecOnMany.rexx 1.2 (2.10.98) by J. Tierney
  2.  
  3.   DiskMaster II Execute On Many  1.2
  4.   10/2/98  J. Tierney
  5.  
  6.   Function:  Execute a command on (possibly) many selected files.
  7.  
  8.   Usage:  DMExecOnMany.rexx <maximum files> <command>
  9.  
  10.     <maximum files> - If positive:  Accept 0 to this many selected files.
  11.                       If zero:      Accept 0 to 999,999 selected files.
  12.                       If -1:        Accept 1 to 999,999 selected files.
  13.                       If < -1:      Accept 1 to Abs(this many) selected files.
  14.  
  15.     <command> - The name of the command to execute, and any options.
  16.  
  17.   Examples:
  18.     DMExecOnMany.rexx 0 SYS:Utilitiess/Visage SHOWINFO WBMONITOR
  19.       - Visage will be run; no files need to be selected.
  20.  
  21.     DMExecOnMany.rexx -3 C:Echo >T:SelectedFiles.txt
  22.       - Up to 3 selected file names will be echoed to T:SelectedFiles.txt.
  23.         There must be at least one file selected.
  24.  
  25.   History:
  26.     - 1.2 (10/2/98):
  27.       - Changed script to use the new improved DirList.
  28.  
  29.     - 1.1 (9/30/97):
  30.       - Added "-1" option for <maximum files>.
  31.       - Limited the command line to 510 characters (<command> will be executed
  32.         multiple times if necessary).
  33.  
  34. */
  35.  
  36. OPTIONS RESULTS
  37.  
  38. PARSE ARG max cmd
  39.  
  40. SELECT
  41.   WHEN max = 0 THEN DO
  42.     max = 999999
  43.     neednofiles = 1
  44.     END
  45.   WHEN max = -1 THEN DO
  46.     max = 999999
  47.     neednofiles = 0
  48.     END
  49.   WHEN max < -1 THEN DO
  50.     max = ABS(max)
  51.     neednofiles = 0
  52.     END
  53.   WHEN max > 0 THEN neednofiles = 1
  54. END
  55.  
  56. cmd = STRIP(cmd, 'B')
  57. IF cmd = '' THEN EXIT 0
  58. cmdlen = LENGTH(cmd)
  59.  
  60.  
  61. line. = ''
  62. lc = 0
  63. linelen = cmdlen
  64. DIRLIST VAR dlist SEL
  65. DO i = 1 TO dlist.name.0
  66.   l = LENGTH(dlist.name.i)
  67.   linelen = linelen + l + 1
  68.   IF linelen > 510 THEN DO
  69.     lc = lc + 1
  70.     linelen = cmdlen
  71.   END
  72.   line.lc = line.lc dlist.name.i
  73. END
  74.  
  75.  
  76. IF neednofiles | line.0 ~= '' THEN DO
  77.   STATUS P
  78.   PRAGMA('D', result)
  79.   DO i = 0 TO lc
  80.     ADDRESS COMMAND cmd || line.i
  81.   END
  82.   DESELECT '*'
  83. END
  84.